import { createVNode, render } from 'vue'
import Confirm from './Confirm.vue'

// 在页面中渲染组件
const cfmDiv = document.createElement('div')
document.body.appendChild(cfmDiv)

export default (txt) => {
  // 以Promise方式，resolve点击确定，reject点击取消
  return new Promise((resolve, reject) => {
    const subFun = () => {
      // 在div中删除div
      render(null, cfmDiv)
      resolve()
    }
    const canFun = () => {
      // 在div中删除div
      render(null, cfmDiv)
      reject()
    }
    const cfmNode = createVNode(Confirm, {txt, subFun, canFun})
    render(cfmNode, cfmDiv)
  })
}
